<template>
	<view >
		<view class="mengbic" v-if="showimg==0" @click="closeFn">
			
		</view>
		<view class="imagw" v-if="showimg==0" @click="tiaozFn">
			<image src="https://medicine.sdshengyue.cn/uploads/images/20240105/20240105091525532312085.png" class="img-laba"></image>
		</view>
		<swiper v-if="newsData.type=='1'"
		    class="swiper h-full bgg"
		    :autoplay="true"
			circular
		>
		    <swiper-item
		        v-for="(item, index) in newsData.pada.trademark"
		        :key="index"
				style="text-align: center;"
		    >
				<image :src="item.img" mode="heightFix" style="width: 100%;"></image>
		    </swiper-item>
		</swiper>
	<view class="tolel">
		<view class="top1" @click="gotoFn" v-if="newsData.type=='1'">
		
			<view class="top-top">
				<view class="top-top-left">
					<image class="gs" :src="newsData.pada.trademark[0].img" mode=""></image>
				</view>
				<view class="top-top-right">
					<view class="gs-name">
						{{newsData.pada.name}}
					</view>
					<view class="gs-type">
					
						<view class="" style="width: 144rpx; height: 38rpx;" v-if="newsData.pada.leixing==0">
							<image style="width: 144rpx; height: 38rpx;" src="../../static/images/qiqi.png" mode=""></image>
						</view>
						<view class="" style="width: 144rpx; height: 38rpx;" v-if="newsData.pada.leixing==1">
							<image style="width: 144rpx; height: 38rpx;" src="../../static/images/index/na.png" mode=""></image>
						</view>
					</view>
				</view>
			</view>
			<view class="top-bottom">
				{{newsData.pada.introduce}}
			</view>
		</view>
		<view class="top" @click="gotoFn1" v-if="newsData.type=='0'">
			<view class="top-top">
				<view class="top-top-left">
					<image class="gs" :src="newsData.pada.avatar" mode=""></image>
				</view>
				<view class="top-top-right">
					<view class="gs-name">
						{{newsData.pada.nickname}}
					</view>
					<view class="gs-type">
					
					</view>
				</view>
			</view>
		
		</view>
		<view class="procure" :class="newsData.type=='0' ? 'procure1' : 'procure'">
			<view class="procure-top">
				<view class="xian">
		
				</view>
				<view class="procure-top-title">
					采购
				</view>
			</view>
			<view class="procure-bottom">
				{{newsData.name}}
				
			</view>
		</view>
		<view class="phone">
			<view class="procure-top">
				<view class="xian">
		
				</view>
				<view class="procure-top-title">
						联系方式
				</view>
				<view class="lookphone" @click="phoneFn">
					查看联系方式
				</view>
			</view>
			<view class="phone-bottom">
				<view class="phone-bottom-item" v-for="(item,index) in newsData.contacts">
					<view class="phone-bottom-item-top">
						<image style="width: 80rpx; height: 80rpx;" src="../../static/images/toi.png" mode=""></image>
					</view>
					<view class="phone-bottom-item-bottom">
						<view class="people">
							{{item.name}}
						</view>
						<view class="tel">
							{{item.tel}}
						</view>
					</view>
					<view class="zhuzhi">
						<image style="width: 52rpx; height: 52rpx; margin-right: 30rpx;" src="../../static/images/fuzhi.png" mode="" @click="copyFn(item.tel)"></image>
						<image style="width: 52rpx; height: 52rpx;" src="../../static/images/phone.png" mode="" @click="phoneFn1(item.tel)"></image>
					</view>
				</view>
			</view>
		</view>
		<view class="procure1">
			<view class="procure-top">
				<view class="xian">
		
				</view>
				<view class="procure-top-title">
					详情信息
				</view>
			</view>
			<view class="procure-bottom">
				{{newsData.xqxx}}
			</view>
		</view>
		<view class="datail">
			<view class="procure-top">
				<view class="xian">
			
				</view>
				<view class="procure-top-title">
					详情信息图片<span style="font-size:26rpx;color: #619ce4;">(点击查看完整图片)</span>
				</view>
			</view>
			<view class="datail-bottom">
				<view class="datail-bottom-item">
					<image v-for="item in newsData.ycxq" :src="item" mode="aspectFill" class="datail-bottom-item-img" @click="yulan(item)"></image>
				</view>
			</view>
		</view>
	</view>
		<view class="notification" v-if="show">
			<view class="notification-top" v-if="userInfo.vip_num!=0&&userInfo.vip_num>0&&userInfo.vip_time==0">
				您确定要查看吗？1/{{userInfo.vip_num}}
			</view>
			<view class="notification-top" v-if="userInfo.vip_time!=0">
				您确定要查看吗？
			</view>
			<view class="notification-top" v-if="userInfo.vip_num==0&&userInfo.vip_num==0&&userInfo.vip_time==0||parseInt(userInfo.vip_time)<=timestamp1">
				请充值会员
			</view>
			<view class="notification-center">
			</view>
			<view class="notification-bottom">
				<view class="notification-bottom-left" @click="quxiaoFn">
					取消
				</view>
				<view class="notification-bottom-right" @click="chakan">
					确定
				</view>
			</view>
		</view>
		<view class="mengbi" v-if="show">
			
		</view>
	</view>
</template>
<!-- <script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script> -->
<script lang="ts" setup>

	import { useUserStore } from '@/stores/user'
	import { ref } from 'vue'
	import { onShow,onLoad,onShareAppMessage,onShareTimeline } from '@dcloudio/uni-app'
	import { storeToRefs } from 'pinia'
	import { getcaigDetail,getqiyeDetail,getlianxiDetail } from '@/api/news'
	//#ifdef H5
	import wechatOa from '@/utils/wechat'
	//#endif
	const userStore = useUserStore()
	const { userInfo, isLogin } = storeToRefs(userStore)
	const showimg=ref('1')
	onShow(() => {
		if(isLogin.value){
			userStore.getUser()
			user_id=userInfo.value.id
			console.log(user_id,'userInfo.value.id');
		}else{
			uni.navigateTo({
				url:"/pages/login/login"
		})
		}
	
		
	})
	
	const yulan=(item)=>{
			wx.previewImage({
					urls: newsData.value.ycxq, //需要预览的图片http链接列表，多张的时候，url直接写在后面就行了
					current: item, // 当前显示图片的http链接，默认是第一个
					success: function (res) { },
		
				})
	}
	
	const show=ref(false)
	const quxiaoFn=()=>{
		show.value = false
	}
	let newsId = ''
	let qId=''
	let user_id=''
	onLoad((options: any) => {
	    newsId = options.id
		// console.log(userId,'userId');
	    getData(newsId)
		// getqiye()
		// console.log(isLogin.value,'isLogin');
		if(!isLogin.value){
			uni.navigateTo({
				url:"/pages/login/login"
			})
		}
	})
	const newsData = ref<any>({})
	const lianxi=ref([])
	const getData = async (id) => {
	    let aa = await getcaigDetail({ id })
		newsData.value=aa
		console.log(newsData.value,'newsData.value');
		newsData.value.contacts=JSON.parse(newsData.value.contacts)
		newsData.value.ycxq=JSON.parse(newsData.value.ycxq)
		if(newsData.value.pada.trademark!=undefined){
			newsData.value.pada.trademark=JSON.parse(newsData.value.pada.trademark)
		}
		// aa.data.contacts=JSON.parse(aa.data.contacts)
		// lianxi.value=aa.data.contacts
		// console.log(lianxi.value,'lianxi.value');
		console.log(newsData.value,'newsData.value');
		qId=newsData.value.q_id
		newsData.value.contacts.forEach(item=>{
		
				item.tel=mobile(item.tel)
				// console.log(item.tel);
			
		})
		
	}


	const getData1 = async (id) => {
	    let aa = await getcaigDetail({ id })
		newsData.value=aa
		newsData.value.contacts=JSON.parse(newsData.value.contacts)
		newsData.value.ycxq=JSON.parse(newsData.value.ycxq)
		if(newsData.value.pada.trademark!=undefined){
			newsData.value.pada.trademark=JSON.parse(newsData.value.pada.trademark)
		}
		// newsData.value.qiye.trademark=JSON.parse(newsData.value.qiye.trademark)
		// aa.data.contacts=JSON.parse(aa.data.contacts)
		lianxi.value=newsData.value.contacts
		qId=newsData.value.q_id
		// console.log(lianxi.value,'lianxi.value');
		// console.log(newsData.value,'newsData.value');
		
	}
	const phoneFn=()=>{
		if(userInfo.value.vip_num==0&&userInfo.value.vip_time==0){
			// uni.showToast({
			// 	title:"请充值会员查看联系方式",
			// 	icon:"none"
			// })
				showimg.value='0'
			return false
		}
		// console.log(1111);
		show.value=true
	}
	const mobile=(data)=>{
		console.log('隐藏电话号码');
		return data.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
	}
	const qiye=ref({})
	// const getqiye=async()=>{
	// 	qiye.value=await getqiyeDetail({
	// 		user_id:userId
	// 	})
	// 	// console.log(data);
	// }
	
	const gotoFn=()=>{
		uni.navigateTo({
			url:"/pages/collection/enterprise_details?qId="+qId
		})
	}
	
	const gotoFn1=()=>{
		uni.navigateTo({
			url:"/pages/collection/yonghu_detile?userId="+user_id
		})
	}
	
	const closeFn=()=>{
		showimg.value=1
	}
	const tiaozFn=()=>{
		uni.navigateTo({
			url:'/pages/user/member'
		})
	}
	// const sharePage =()=>{
	// 	const shareConfig={
	// 		title:'果意园',
	// 		path:'/pages/news_detail/news_detail'
	// 	}
	// 	 uni.share(shareConfig);
	// }
	const goodsContentConv=(html)=>{
	var GRT = [
						// img 样式
						['img', "max-width:100%;height:auto;"],
					];
					for (let i = 0; i < GRT.length; i++) {
						html = html.replace(new RegExp('<' + GRT[i][0] + '>|<' + GRT[i][0] + ' (.*?)>', 'gi'), function(word) {
							// 分析 dom 上是否带有 style=""
							if (word.indexOf('style=') != -1) {
								var regIn = new RegExp('<' + GRT[i][0] + '(.*?)style="(.*?)"(.*?)(/?)>', 'gi');
								return word.replace(regIn, '<' + GRT[i][0] + '$1style="$2 ' + GRT[i][1] + '"$3$4>');
							} else {
								var regIn = new RegExp('<' + GRT[i][0] + '(.*?)(/?)>', 'gi');
								return word.replace(regIn, '<' + GRT[i][0] + '$1 style="' + GRT[i][1] + '$2">');
							}
						});
					}
					return html;
		}
		let timestamp1=ref(0)
		const chakan=async()=>{
			var timestamp = Math.floor(Date.now()/1000);
			timestamp1.value=timestamp
			console.log(timestamp,'timestamp');
			if(userInfo.value.vip_time!=0){
				console.log(parseInt(userInfo.value.vip_time),'parseInt(userInfo.value.vip_time)');
				// console.log();
				if(parseInt(userInfo.value.vip_time)>=timestamp){
					// userInfo.value.contacts=lianxi.value
					let aa=await getData1(newsId)
				}else{
					uni.showToast({
						title:"您的会员已到期",
						icon:"none"
					})
				}
			}
			if(userInfo.value.vip_num!=0&&userInfo.value.vip_time==0&&userInfo.value.vip_num>0){
				let a=await getlianxiDetail()
				// userInfo.value.contacts=lianxi.value
				let aa=await getData1(newsId)
				// console.log(userInfo.value.contacts,'userInfo.value.contacts');
				// console.log(a,'减一');
				// return false
				console.log('减一');
			}
			// if(userInfo.value.vip_num==0&&userInfo.value.vip_num==0&&userInfo.value.vip_time==0){
			// 	uni.navigateTo({
			// 		url:"/pages/user/member"
			// 	})
			// 	console.log('111');
			// 	// return false
			// }
			show.value=false
		}
		const copyFn=(tel:any)=>{
				// uni.setClipboardData({
				// 				data: tel,
				// 				success: () => {
				// 					uni.showToast({
				// 						title: '复制成功'
				// 					})
				// 				}
				// 			})
				// 			})
				const str = tel;
				const inputo = document.createElement("input");
				document.body.appendChild(inputo);
				inputo.value = str;
				inputo.setAttribute('readOnly', 'readOnly')
				inputo.select();
				document.execCommand("Copy");
				document.body.removeChild(inputo);
				uni.showToast({
										title: '复制成功'
									})
					
				
		
		}
		const phoneFn1=(tel:any)=>{
			if(userInfo.value.vip_num==0&&userInfo.value.vip_time==0){
				showimg.value='0'
				return false
			}
				let platform = uni.getSystemInfoSync().platform
				switch (platform) {
					case 'android':
						uni.showActionSheet({
						    itemList: [tel,'呼叫'],
						    success:function(res){
								console.log(res);
								if(res.tapIndex==1){
									plus.device.dial(tel,false)        
								}
						    },
						    complete: function(res) {
						       console.log("安卓失败",res)
						    }
						})
						break;
					case 'ios':
						// 使用uni-app提供的借口
						uni.makePhoneCall({
							phoneNumber: tel
			 
						})
						break;
					default:
		}
		}
</script>

<style lang="scss" scoped>
	@media screen and (max-width:414rpx) {
		.tolel .top1 .top-bottom{
			
		      height: 3.9rem;
		}
		}
	@media screen and (max-width:390px) {
		.tolel .top1 .top-bottom{
			
		      height: 4.2rem;
		}
		}
		@media screen and (max-width:375px) {
				 .tolel .top1 .top-bottom{
					 
		      height: 4rem;
				 }
		   }
	@media screen and (max-width:360px) {
		.tolel .top1 .top-bottom{
			height: 4rem;
		}
	   }
	

	.bgg {
		// position: fixed;
		width: 100%;
		// top: 0;
		// height: 534rpx;
		height: 390rpx;
		z-index: -1;
	}
	.zhuzhi{
		margin-left: auto;
		margin-top: 10rpx;
	}
	.lookphone{
		width: 208rpx;
		height: 64rpx;
		background-color: #19C280;
		text-align: center;
		line-height: 64rpx;
		border-radius: 8rpx;
		font-size: 28rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
		// margin-right: auto;
		// text-align: right;
		margin-left: 295rpx;
	}
	.mengbic{
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		z-index: 2;
		background: rgba(0,0,0,0.2);
	}
	.imagw{
		width: 750rpx;
		height: 730rpx;
		position: absolute;
		top: 274rpx;
		left: 50%;
		transform: translate(-50%,0);
		z-index:3
	}
	.img-laba{
		width: 750rpx;
		height: 730rpx;
	}
	.share{
		width: 216rpx;
		height: 82rpx;
		position: fixed;
		right: 20rpx;
		bottom:110rpx;
	}
	.datail{
		margin-top: 48rpx;
		margin-bottom: 50rpx;
		padding-bottom: 100rpx;
		.procure-top {
			padding-bottom: 16rpx;
			font-size: 32rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			color: #333333;
			display: flex;
			border-bottom: 2rpx solid #F5F5F5;
			.xian {
				width: 6rpx;
				height: 28rpx;
				background: #19C181;
				border-radius: 6rpx 6rpx 6rpx 6rpx;
				opacity: 1;
				margin-top: 11rpx;
				margin-right: 8rpx;
			}
		
		}
		.datail-bottom{
			padding: 20rpx;
			background: #FFFFFF;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			opacity: 1;
			.datail-bottom-item{
				
				padding: 20rpx;
				border-radius: 8rpx 8rpx 8rpx 8rpx;
				opacity: 1;
				border: 2rpx solid #F5F5F5;
				text-align: center;
				.datail-bottom-item-img{
					width: 180rpx;
					height: 180rpx;
					
					margin-right: 3rpx;
				}
			}
		}
	}
	.mengbi {
		position: fixed;
		top: 0;
		left: 0;
		bottom: 0;
		right: 0;
		z-index: 33;
		background-color: rgba(0, 0, 0, 0.4);
	}
	.tolel {
		width: 92%;
		margin-left: 4%;
		margin-right: 4%;
		.top1 {
			position: absolute;
			background-color: #fff;
			// height: 240rpx;
			height:329rpx;
			padding: 28rpx;
			top: 346rpx;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			left:4%;
			right:4%;
			.top-top {
				display: flex;

				.top-top-left {
					.gs {
						width: 108rpx;
						height: 108rpx;
					}
				}

				.top-top-right {
					padding-left: 20rpx;
					flex: 1;

					.gs-name {
						font-size: 32rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						color: #333333;
						margin-bottom: 12rpx;
					}

					.gs-type {
						width: 144rpx;
						height: 38rpx;
						// background: rgba(25, 194, 129, 0.05);
						border-radius: 4rpx 4rpx 4rpx 4rpx;
						opacity: 1;
						display: flex;
						justify-content: center;
						line-height: 38rpx;
						font-size: 22rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						// color: #19C281;

						.qi {
							display: inline-block;

							.qiye {
								width: 28rpx;
								height: 28rpx;
								vertical-align: middle;
							}
						}

					
					}

				}
			}
			

			.top-bottom {
				width: 100%;
				
				// height: 130rpx;
				// height: 4.04rem;
				font-size: 24rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				color: #AAAAAA;
				display: -webkit-box;
				/*弹性伸缩盒子模型显示*/
				-webkit-box-orient: vertical;
				/*排列方式*/
				-webkit-line-clamp: 4;
				/*显示文本行数*/
				overflow: hidden;
				/*溢出隐藏*/
			}
		}
		.top {
			background-color: #fff;
			height: 170rpx;
			padding: 28rpx;
			margin-top: 28rpx;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
		
			.top-top {
				display: flex;
		
				.top-top-left {
					.gs {
						width: 108rpx;
						height: 108rpx;
					}
				}
		
				.top-top-right {
					padding-left: 20rpx;
					flex: 1;
		
					.gs-name {
						font-size: 32rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						color: #333333;
						// margin-bottom: 12rpx;
						line-height: 118rpx;
					}
		
				}
			}
		
			.top-bottom {
				width: 100%;
				height: 66rpx;
				font-size: 24rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				color: #AAAAAA;
				display: -webkit-box;
				/*弹性伸缩盒子模型显示*/
				-webkit-box-orient: vertical;
				/*排列方式*/
				-webkit-line-clamp: 4;
				/*显示文本行数*/
				overflow: hidden;
				/*溢出隐藏*/
			}
		}

		.procure {
			// margin-top: 28rpx;
			margin-top:310rpx;
			// height: 380rpx;
			background: #FFFFFF;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			opacity: 1;
			padding: 20rpx;

			.procure-top {
				padding-bottom: 16rpx;
				font-size: 32rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				color: #333333;
				display: flex;
				padding-bottom: 20rpx;
				border-bottom: 2rpx solid #F5F5F5;

				.xian {
					width: 6rpx;
					height: 28rpx;
					background: #19C181;
					border-radius: 6rpx 6rpx 6rpx 6rpx;
					opacity: 1;
					margin-top: 11rpx;
					margin-right: 8rpx;
				}

			}

			.procure-bottom {
				padding: 20rpx;
				background: #F8F8F8;
				border-radius: 8rpx 8rpx 8rpx 8rpx;
				opacity: 1;
				font-size: 28rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				color: #777777;
				line-height: 33rpx;

			}

		}
		.procure1 {
			margin-top: 28rpx;
			// margin-top:298rpx;
			// height: 380rpx;
			background: #FFFFFF;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			opacity: 1;
			padding: 20rpx;

			.procure-top {
				padding-bottom: 16rpx;
				font-size: 32rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				color: #333333;
				display: flex;
				padding-bottom: 20rpx;
				border-bottom: 2rpx solid #F5F5F5;

				.xian {
					width: 6rpx;
					height: 28rpx;
					background: #19C181;
					border-radius: 6rpx 6rpx 6rpx 6rpx;
					opacity: 1;
					margin-top: 11rpx;
					margin-right: 8rpx;
				}

			}

			.procure-bottom {
				padding: 20rpx;
				background: #F8F8F8;
				border-radius: 8rpx 8rpx 8rpx 8rpx;
				opacity: 1;
				font-size: 28rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				color: #777777;
				line-height: 33rpx;

			}

		}
		.phone {
			margin-top: 28rpx;
			// height: 380rpx;
			background: #FFFFFF;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			opacity: 1;
			padding: 20rpx;

			.procure-top {
				padding-bottom: 16rpx;
				font-size: 32rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				color: #333333;
				display: flex;
				border-bottom: 2rpx solid #F5F5F5;
				align-items: center;
				.xian {
					width: 6rpx;
					height: 28rpx;
					background: #19C181;
					border-radius: 6rpx 6rpx 6rpx 6rpx;
					opacity: 1;
					margin-top: 11rpx;
					margin-right: 8rpx;
				}

			}

			.phone-bottom{
				// margin-top: 20rpx;
				.phone-bottom-item{
					height: 80rpx;
					display: flex;
					margin-top: 20rpx;
					.phone-bottom-item-bottom{
						margin-left: 20rpx;
						.people{
							font-size: 28rpx;
							font-family: PingFang SC, PingFang SC;
							font-weight: 500;
							color: #333333;
						}
						.tel{
							margin-top: 4rpx;
							font-size: 24rpx;
							font-family: PingFang SC, PingFang SC;
							font-weight: 400;
							color: #777777;
							
						}
					}
				}
			}
		}
	}
	.notification {
		position: fixed;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		width: 614rpx;
		// height: 282rpx;
		background: #FFFFFF;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		z-index: 43;
	
		.notification-top {
			text-align: center;
			margin-top: 36rpx;
			font-size: 32rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			color: #333333;
	
		}
	
		.notification-center {
			text-align: center;
			font-size: 28rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			color: #999999;
			margin-top: 22rpx;
			margin-bottom: 34rpx;
	
		}
	
		.notification-bottom {
			display: flex;
			justify-content: space-evenly;
			text-align: center;
			align-items: center;
			border-top: 1rpx solid #EEEEEE;
			height: 126rpx;
		
			.notification-bottom-left {
				width: 40%;
				height: 70rpx;
				line-height: 70rpx;
				border-radius: 10rpx;
				font-size: 28rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				color: #333;
				background-color: #efefef;
		
			}
		
			.notification-bottom-right {
				width: 40%;
				height: 70rpx;
				line-height: 70rpx;
				border-radius: 10rpx;
				font-size: 28rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				color: #fff;
				background-color: #19C181;
		
			}
		}
	}
</style>